package com.ruoyi.result.awardPersonal.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.result.awardPersonal.domain.ResultPersonalAward;
import com.ruoyi.result.awardPersonal.domain.dto.ResultPersonalAwardDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 个人获奖Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-14
 */
@Mapper
public interface ResultPersonalAwardMapper
{
    /**
     * 查询个人获奖
     *
     * @param id 个人获奖主键
     * @return 个人获奖
     */
    public ResultPersonalAward selectResultPersonalAwardById(Long id);

    /**
     * 查询个人获奖列表
     *
     * @param resultPersonalAward 个人获奖
     * @return 个人获奖集合
     */
    public List<ResultPersonalAward> selectResultPersonalAwardList(ResultPersonalAwardDTO resultPersonalAward);

    /**
     * 新增个人获奖
     *
     * @param resultPersonalAward 个人获奖
     * @return 结果
     */
    public int insertResultPersonalAward(ResultPersonalAward resultPersonalAward);

    /**
     * 修改个人获奖
     *
     * @param resultPersonalAward 个人获奖
     * @return 结果
     */
    public int updateResultPersonalAward(ResultPersonalAward resultPersonalAward);

    /**
     * 删除个人获奖
     *
     * @param id 个人获奖主键
     * @return 结果
     */
    public int deleteResultPersonalAwardById(Long id);

    /**
     * 批量删除个人获奖
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultPersonalAwardByIds(Long[] ids);

    List<ResultPersonalAward> selectResultPersonalAwardByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_personal_award WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(award_time) as year, COUNT(*) as count FROM result_personal_award " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(award_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(award_time) as year, COUNT(*) as count FROM result_personal_award " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(award_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);

    List<ResultPersonalAward> selectResultPersonalAwardListByDept(ResultPersonalAwardDTO resultPersonalAward);
}
